package com.dxd.onlineshop.controller;

import com.dxd.onlineshop.pojo.Product;
import com.dxd.onlineshop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/search")
public class SearchController {

    @Autowired
    private ProductService productService;

    //搜索商品
    @GetMapping
    public ResponseEntity<List<Product>> searchProducts(
            @RequestParam String query,
            @RequestParam(required = false) Integer categoryId) {
        List<Product> results = productService.searchProducts(query, categoryId);
        return ResponseEntity.ok(results);
    }
}